package com.gogowan.agroenterprise.widget.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.model.MarketRecode;

import java.util.List;

public class MainListViewAdapater extends BaseAdapter {
    private LayoutInflater inflater;
    private Context context;
    private List<MarketRecode> list;
    public MainListViewAdapater(Context context, List<MarketRecode> list){
        this.context=context;
        inflater= LayoutInflater.from(context);
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Houlder houlder=null;
        if ( convertView==null){
            convertView=inflater.inflate(R.layout.mainlistitemactivity,null);
            houlder=new Houlder();
            houlder.DealerName_Tv=(TextView)convertView.findViewById(R.id.mainlist_item_Dealer_Name_Tv);
            houlder.Station_Tv=(TextView)convertView.findViewById(R.id.mainlist_item_station_Tv);
            houlder.Time_Tv=(TextView)convertView.findViewById(R.id.mainlist_item_Time_Tv);
            convertView.setTag(houlder);
        }else {
            houlder=(Houlder) convertView.getTag();
        }
        houlder.DealerName_Tv.setText(list.get(position).getDealerName());
        houlder.Time_Tv.setText(list.get(position).getCheckTime());
        if (list.get(position).getStatus()==0){
            houlder.Station_Tv.setTextColor(context.getResources().getColor(R.color.red));
            houlder.Station_Tv.setText("异常");
        }else {
            houlder.Station_Tv.setTextColor(context.getResources().getColor(R.color.text_02));
            houlder.Station_Tv.setText("正常");
        }
        return convertView;
    }
    class Houlder{
        TextView DealerName_Tv,Station_Tv,Time_Tv;
    }
}
